#include <iostream>
#include <thread>
#include <future>
#include <string>
 
std::string process(std::string token) {
    std::string result(token);
    std::transform(token.begin(),token.end(),result.begin(),std::toupper);
    return result;
}

int main()
{
    std::packaged_task<std::string(std::string)> task(process);
    auto thread_func = [&](std::string token) {
        std::this_thread::sleep_for(std::chrono::seconds(2));
        task(token);
        while(1)
        {
            std::this_thread::sleep_for(std::chrono::seconds(1));
        }
    };
    std::thread th(thread_func, "hello");

    std::cout << "try to get result ..." << std::endl;
    std::future<std::string> result = task.get_future();
    std::string data = result.get();
    std::cout << "result: " << data << std::endl;
    th.join();

    return 0;
}
